package com.ymttest.database.mongo.jproduct;

import com.ymatou.tool.Logger;
import com.ymt.database.MongoDBDriver;
import com.ymttest.database.mongo.YmtMongoDriverFactroy;
import com.ymttest.utils.MapUtil;

import java.util.ArrayList;
import java.util.Map;

public class ProductTimeStampWapper {
private MongoDBDriver mdd = YmtMongoDriverFactroy.getInstance_YmtProductDBdriverNewJava("ProductTimeStamp");
private MongoDBDriver mdd1 = YmtMongoDriverFactroy.getInstance_YmtProductDBdriverNewJava("ActivityProducts");

	public boolean updateTime(Integer aid,Map<String, Object> updateMap) throws Exception{
		return  mdd1.update(MapUtil.hashMap("inaid",aid), updateMap).isUpdateOfExisting();
	}
	
	public Map<String,Object> getByProductId(String productId) throws Exception {
		ArrayList<Map> list = mdd.selectPartLimitToMap("{\"spid\":\"" + productId + "\"}",1);
	    
	    return list.size()>0?list.get(0):null;
	}
	     
	public int getCountByProductId(String productId) throws Exception{
		return mdd.selectPartLimitToMap("{\"spid\":\"" + productId + "\"}",50).size();
	}
	
	
	public boolean update(Map<String, Object> searchMap,Map<String, Object> updateMap) throws Exception{
		return  mdd.update(searchMap, updateMap).isUpdateOfExisting();
	}
	
	public boolean update(String productId,Map<String, Object> updateMap) throws Exception{
		return  mdd.update(MapUtil.hashMap("spid",productId), updateMap).isUpdateOfExisting();
	}
	
	
	public boolean delete(String productId) throws Exception {
		return mdd.delete("{\"spid\":\"" + productId + "\"}").isUpdateOfExisting();
	}
	

	
	public static void main(String[] args) throws Exception {
		Map map = new ProductTimeStampWapper().getByProductId("p1076227");
		Logger.debug(map);
		System.out.println("map:" + map);
	}
	
	
}
